package ee.karileet.productcatalogue.dao.impl;

// Generated Dec 1, 2013 7:35:28 PM by Hibernate Tools 3.4.0.CR1

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.criterion.SimpleExpression;

import ee.karileet.productcatalogue.dao.IGroupHome;
import ee.karileet.productcatalogue.model.Group;
import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Group.
 * @see ee.karileet.productcatalogue.model.Group
 * @author Hibernate Tools
 */
public class GroupHome extends GenericHome implements IGroupHome {
	private static final Log log = LogFactory.getLog(GroupHome.class);

	public GroupHome() {
		super("ee.karileet.productcatalogue.model.Group");
	}
	
	public void persist(Group transientInstance) {
		log.debug("persisting Group instance");
		try {
			sessionFactory.openSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Group instance) {
		log.debug("attaching dirty Group instance");
		try {
			sessionFactory.openSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@SuppressWarnings("deprecation")
	public void attachClean(Group instance) {
		log.debug("attaching clean Group instance");
		try {
			sessionFactory.openSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Group persistentInstance) {
		log.debug("deleting Group instance");
		try {
			sessionFactory.openSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Group merge(Group detachedInstance) {
		log.debug("merging Group instance");
		try {
			Group result = (Group) sessionFactory.openSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Group findById(int id) {
		log.debug("getting Group instance with id: " + id);
		try {
			Group instance = (Group) sessionFactory.openSession().get(
					entityName, id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Group> findByExample(Group instance) {
		log.debug("finding Group instance by example");
		try {
			List<Group> results = (List<Group>) sessionFactory
					.getCurrentSession()
					.createCriteria(
							entityName)
					.add(create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Group> find(List<SimpleExpression> expressions) {
		return (List<Group>) super.find(entityName, expressions);
	}

	@SuppressWarnings("unchecked")
	public List<Group> findAll() {
		return (List<Group>) super.findAll(entityName);
	}
	
	@Override
	public void save(Group g) {
		super.save(g);
	}
}
